package com.xunwulian.cmeb.command;

import com.google.gson.Gson;
import com.xunwulian.base.exception.ErrorCodeException;
import org.json.JSONArray;

/**
 * GPRS在线信息
 */
public class GprsInfoCommand extends Command {

    private String msisdn;

    public GprsInfoCommand(Receiver receiver, String msisdn) {
        super(APICode.GPRSONLINEINFO, receiver);
        this.msisdn = msisdn;
    }

    @Override
    public String getParam() {
        return "msisdn=" + msisdn;
    }

    @Override
    public GprsInfoEntity execute() throws ErrorCodeException {
        JSONArray result = receiver.actionPost(api, getParam());

        GprsInfoEntity gprsInfo = GprsInfoEntity.getDefault();
        if (null != result && result.length() != 0) {
            Gson gson = new Gson();
            gprsInfo = gson.fromJson(result.getJSONObject(0).toString(), GprsInfoEntity.class);
        }
        return gprsInfo;
    }
}
